home *** CD-ROM | disk | FTP | other *** search
- ' *** DIRDEMO.BAS ***
- '
- ' Fairchild Computer Services
- ' Route 5, Box 523-12
- ' Wills Point, TX 75169
- ' (903) 873-2114
- '
- '**************************** GENERAL NOTATIONS ***************************
- '
- '
- ' This program is a half-way decent example of how to use dir.bas.
- '
- '
- '
- ' Enjoy!! -jmf
- '
- '
- '**************************************************************************
-
- '************************** COMMAND LINE CREATION *************************
- ' To make a standalone executable:
- ' First, create DIR.QLB & DIR.LIB (see COMMAND LINE CREATION in DIR.BAS);
- ' BC DIRDEMO/O/AH/T/C:512;
- ' LINK DIRDEMO/EX/NOE/NOD:BRUN45.LIB
- ' DIRDEMO
- ' NUL
- ' BCOM45.LIB+
- ' DIR.LIB
- '**************************************************************************
-
- '************************** FUNCTION DECLARATIONS *************************
-
- DECLARE FUNCTION CreateBoxLine$ (RecordNumber%) 'Creates new line in box
- DECLARE FUNCTION LastOccurrence% (text$, LookString$) 'Finds string
- DECLARE FUNCTION VideoSegment! () 'Retrieves video memory segment
-
- '**************************************************************************
-
- '************************* SUBROUTINE DECLARATIONS ************************
-
- DECLARE SUB Center (row%, lcol%, rcol%, text$) 'Centers text
- DECLARE SUB ClearBox (x1%, y1%, x2%, y2%) 'Clears window area
- DECLARE SUB CreateBox () 'Creates directory box
- DECLARE SUB DirTotals (Directory$) 'Returns totals for files in dir
- DECLARE SUB DisplayDir (DirEntry%) 'Display dir entry info in box
- DECLARE SUB DisplayHelp () 'Display help line(s)
- DECLARE SUB DisplayDirStats () 'Display directory entry stats
- DECLARE SUB DisplayMemStats () 'Display memory statistics
- DECLARE SUB DisplayTotals () 'Display totals info
- DECLARE SUB DoKeystroke () 'Sub to evaluate & do keystroke(s)
- DECLARE SUB ExitLogo () 'Let em know who we are...
- DECLARE SUB GetDir () 'Gets directory entry information
- DECLARE SUB GrandTotals (Directory$) 'Sub to calc dir and sub-dirs
- DECLARE SUB ReverseLine (row%, lcol%, rcol%) 'Used to reverse video a line
- DECLARE SUB ScrollDown (text$) 'Scrolls box lines down 1
- DECLARE SUB ScrollUp (text$) 'Scrolls box lines up 1
- DECLARE SUB SortDir (count%) 'Used to sort all directory entries
-
- '**************************************************************************
-
- '******************* CONSTANT/INCLUDE FILE DECLARATIONS *******************
-
- ' $INCLUDE: 'DIR.INC' 'Use this for DIR.BAS declares, etc.
- ' $INCLUDE: 'QB.BI' 'Use this for interrupt calls
-
- ' The following are used by DrawBox
- CONST coloronly% = 1 'Color box only (don't erase chars)
- CONST fillonly% = 2 'Fill box only (erase all chars)
- CONST colorandfill% = 3 'Color box and erase box contents
- CONST reverseonly% = 4 'Reverse color of box only
- CONST reverseandfill% = 5 'Reverse color and fill it
-
- ' The following are used by DoKeystroke (Action%)
- CONST NextDir% = 1 'Do next dir call
- CONST EndIt% = 2 'Goto end of program
-
- '**************************************************************************
-
- '************************ DATABASE (TYPE) LAYOUTS *************************
- '**************************************************************************
-
- '**************** DECLARE GLOBAL (COMMON) SHARED VARIABLES ****************
- '**************************************************************************
-
- '******************** DECLARE LOCAL (SHARED) VARIABLES ********************
-
- DIM SHARED Action% 'Action to be done after DoKeyStroke
- DIM SHARED BottomDisplay% 'Last MyDir entry in window
- DIM SHARED BoxLine$(24) 'Holds lines for box printing
- DIM SHARED BoxLength%, BoxHeight% 'Length and height of box
- DIM SHARED BoxRow%, BoxCol% 'Start position of box row & column
- DIM SHARED BoxCol1%, BoxCol2% 'Start and end position of box cols
- DIM SHARED DirChoice% 'MyDir() choice
- DIM SHARED HoldCount% 'Dir Entry counter
- DIM SHARED FirstPrintRow% 'Start screen line of box line prints
- DIM SHARED LastBoxRow% 'Ending screen line of box
- DIM SHARED LastPrintLine% 'Ending position of box line prints
- DIM SHARED LastPrintRow% 'Ending screen line of box line prints
- DIM SHARED MainBg%, MainFg% 'Screen colors
- DIM SHARED MyDirCount% 'Count of (sub-)dirs in current dir
- DIM SHARED NewLine%, OldLine% 'Box print line number holder var's
- DIM SHARED SubDir% 'Sub directory flag
- DIM SHARED TopDisplay% 'Top MyDir entry in window
- DIM SHARED FC, SC, TS 'Share count variables
-
- '**************************************************************************
-
- '**************************** CREATE VARIABLES ****************************
- '**************************************************************************
-
- '*************************** DATA DECLARATIONS ****************************
- '**************************************************************************
-
- '************************* MAIN SUBROUTINE CALLS **************************
- Main:
- ' The following are the changeable attributes
- MainBg% = 7 'Main (screen) background color
- MainFg% = 0 'Main (screen) foreground color
- BoxRow% = 1 'Row of upper left corner of box
- BoxCol% = 1 'Column of upper left corner of box
- BoxHeight% = 13 'Height of box (from BoxRow%)
-
- ' Let's get started...
- COLOR MainBg%, MainFg% 'Color screen
- CLS 'Clear screen
-
- MainGetDir:
- HoldCount% = DirCount%("*.*") 'Do a directory entry count
- REDIM SHARED MyDir(HoldCount%) AS DirType 'Dimension array
- CreateBox 'Paint box to screen
- Center FirstPrintRow%, BoxCol1%, BoxCol2%, "Directory Entries Found : " + STR$(HoldCount%)
- GetDir 'Get the entries
- OldLine% = 1: NewLine% = 1 'Init reverse bar counters
- DirChoice% = 1 'Number of Mydir() record
- DisplayDir (DirChoice%) 'Display current entries in box
- ReverseLine FirstPrintRow%, BoxCol1%, BoxCol2% 'Highlight first entry
- DisplayDirStats 'Display directory stat info
- DisplayMemStats 'Display memory stat info
- DisplayTotals 'Display other totals stats
- DisplayHelp 'Display help info
- DoKeystroke 'Get/do user's keystroke(s)
- SELECT CASE Action% 'When done...any action to take?
- CASE False% 'No.
- GOTO EndProgram ' we be done...
- CASE NextDir% 'Yes.
- GOTO MainGetDir ' we got another dir to display
- CASE EndIt% 'Yes.
- GOTO EndProgram ' bye, bye...
- END SELECT
-
- '**************************************************************************
-
- '*************************** DATA DECLARATIONS ****************************
- '**************************************************************************
-
- '***************************** EXIT ROUTINES ******************************
- EndProgram:
- ExitLogo
- END
- '**************************************************************************
-
- SUB Center (row%, lcol%, rcol%, text$)
-
- ' This subroutine will center text$ on row%, between lcol% and rcol%
-
- col% = lcol% + INT((rcol% - lcol% - LEN(text$)) / 2) + 2 'Calc cursor pos
- LOCATE row%, col% 'Position cursor
- PRINT text$; 'Print actual text
-
- END SUB
-
- SUB ClearBox (x1%, y1%, x2%, y2%)
-
- ' This subroutine will clear the contents of a window.
-
- InRegsX.AX = &H600 'function 6 + number of scroll lines
- fg% = MainBg% * 256 'Calc BH foreground
- bg% = MainFg% * 4096 'Calc BH background
- InRegsX.BX = fg% + bg% 'Blanked line color
- CH% = x1% * 256 'CH=top row
- InRegsX.CX = CH% + y1% 'CL=left column
- DH% = (x2% - 1) * 256 'DH=bottom row
- InRegsX.DX = DH% + y2% 'DL=right column
- CALL INTERRUPTX(&H10, InRegsX, OutRegsX) 'Call interrupt 16
-
- END SUB
-
- SUB CreateBox
-
- ' This subroutine will create the box used for the directory display
- ' and manipulation.
-
- a2$ = CHR$(205) 'Double across line
- br$ = CHR$(179) 'Save bar variable
- s1$ = " " 'Save space variable
- t1$ = null$ 'Temporary variable
- xt$ = CHR$(209) 'Single across, middle down line
- xl$ = CHR$(207) 'Single across, middle up
- BoxLength% = 47 'Fixed (non-changeable) box length
- GOSUB CheckBoxDimensions 'Ensure good dimensions
- FirstPrintRow% = BoxRow% + 4 'First physical row for box prints
- LastBoxRow% = BoxRow% + BoxHeight% 'Last physical row of box
- BoxCol1% = BoxCol% 'Save left column for ReverseLine
- BoxCol2% = BoxCol1% + BoxLength% 'Save right column for ReverseLine
-
- BoxLine$(1) = CHR$(213) + STRING$(48, 205) + CHR$(184)
- BoxLine$(2) = br$ + SPACE$(48) + br$
- FOR c% = 1 TO 5: t1$ = t1$ + xt$ + a2$: NEXT
- BoxLine$(3) = CHR$(198) + STRING$(12, 205) + xt$ + STRING$(9, 205) + xt$ + STRING$(8, 205) + xt$ + STRING$(6, 205) + t1$ + CHR$(181)
- t$ = br$ + " Name " + br$ + " Size " + br$ + " Date " + br$ + " Time "
- BoxLine$(4) = t$ + br$ + "R" + br$ + "H" + br$ + "S" + br$ + "A" + br$ + "D" + br$
- t1$ = null$
- FOR c% = 1 TO 5: t1$ = t1$ + s1$ + br$: NEXT
- FOR c% = 5 TO BoxHeight%
- BoxLine$(c%) = br$ + SPACE$(12) + br$ + SPACE$(9) + br$ + SPACE$(8) + br$ + SPACE$(6) + br$ + t1$
- NEXT
- t1$ = null$
- FOR c% = 1 TO 5: t1$ = t1$ + xl$ + a2$: NEXT
- BoxLine$(BoxHeight% + 1) = CHR$(212) + STRING$(12, 205) + xl$ + STRING$(9, 205) + xl$ + STRING$(8, 205) + xl$ + STRING$(6, 205) + t1$ + CHR$(190)
- FOR c% = BoxRow% TO BoxRow% + BoxHeight% + 1
- LOCATE c%, BoxCol%
- PRINT BoxLine$(c% - BoxRow% + 1);
- NEXT
- GOTO ExitCreateBox
-
- CheckBoxDimensions:
- SELECT CASE BoxCol%
- CASE IS < 1
- BoxCol% = 1
- CASE IS > 80 - BoxLength% - 2
- BoxCol% = 80 - BoxLength% - 2
- END SELECT
- SELECT CASE BoxRow% + BoxHeight%
- CASE IS > 14
- BoxHeight% = 14 - BoxRow%
- END SELECT
- SELECT CASE BoxRow%
- CASE IS < 1
- BoxRow% = 1
- CASE IS > 8
- BoxRow% = 8
- END SELECT
- SELECT CASE BoxHeight%
- CASE IS < 6
- BoxHeight% = 6
- CASE IS > 14
- BoxHeight% = 14
- END SELECT
- RETURN
-
- ExitCreateBox:
- END SUB
-
- FUNCTION CreateBoxLine$ (RecordNumber%)
-
- ' This function will build a line to be displayed within the box
- ' created by CreateBox
-
- as$ = "*" 'Save asterisk variable
- br$ = CHR$(179) 'Save up-down bar variable
- s1$ = " " 'Save space variable
- t1$ = null$ 'Temporary save variable
- REDIM f$(5) 'DIMension flag array
- FOR c% = 1 TO 5: f$(c%) = s1$: NEXT 'Initialize flags
- t$ = MyDir(RecordNumber%).EntryName + br$ 'Start row w/entry and bar
- IF MyDir(RecordNumber%).DirectoryFlag THEN 'Directory?
- t$ = t$ + " < DIR > " 'If directory, so display
- f$(5) = as$ 'Set flag for display on
- ELSE 'If not...
- t$ = t$ + ConvertSize$(MyDir(RecordNumber%).EntrySize) 'Display size
- END IF
- t$ = t$ + br$ + ConvertDate$(MyDir(RecordNumber%).EntryDate)
- t$ = t$ + br$ + ConvertTime$(MyDir(RecordNumber%).EntryTime) + br$
- IF MyDir(RecordNumber%).ReadOnlyFlag THEN f$(1) = as$
- IF MyDir(RecordNumber%).HiddenFlag THEN f$(2) = as$
- IF MyDir(RecordNumber%).SystemFlag THEN f$(3) = as$
- IF MyDir(RecordNumber%).ArchiveFlag THEN f$(4) = as$
- FOR c% = 1 TO 5: t1$ = t1$ + f$(c%) + br$: NEXT 'Try again
- t$ = t$ + t1$ 'Make final variable
-
- CreateBoxLine$ = t$ ' and return it
-
- END FUNCTION
-
- SUB DisplayDir (DirEntry%)
-
- ' This subroutine will build the directory entry display
-
- TopDisplay% = DirEntry%
- IF HoldCount% + SubDir% <= BoxHeight% - FirstPrintRow% + BoxRow% THEN
- LastPrintRow% = FirstPrintRow% + HoldCount% + SubDir%
- LastPrintLine% = HoldCount% + SubDir%
- ELSE
- LastPrintRow% = BoxRow% + BoxHeight% - 1
- LastPrintLine% = BoxHeight% - FirstPrintRow% + BoxRow%
- END IF
- t$ = CurrentDir$
- IF LEN(t$) >= BoxLength% THEN
- t$ = LEFT$(t$, INSTR(t$, ":")) + "\..." + RIGHT$(t$, BoxLength% - 5)
- END IF
- Center BoxRow% + 1, BoxCol1%, BoxCol2%, t$
- FOR c% = 0 TO LastPrintLine% - 1
- LOCATE c% + FirstPrintRow%, BoxCol% + 1
- PRINT CreateBoxLine$(DirEntry% + c%);
- NEXT
- BottomDisplay% = DirEntry% + LastPrintLine% - 1
-
- END SUB
-
- SUB DisplayDirStats
-
- BoxCol3% = BoxCol2% + 3 'Save column variable for printing
- br$ = CHR$(179) + " " 'Bar plus space
- fl% = 3 'Set MaskIt$ field length variable
- HS = 0 'Initialize hidden size variable
- NS = 0 'Initialize non-dir size variable
- RS = 0 'Initialize read-only size variable
- XS = 0 'Initialize archived size variable
- TR% = 0 'Initialize total reserved counter
- TH% = 0 'Initialize total hidden counter
- TS% = 0 'Initialize total system counter
- TA% = 0 'Initialize total archived counter
- pc% = 1
-
- x1% = BoxRow% 'Upper row of display area
- y1% = BoxCol3% - 1 'Left col of display area
- x2% = x1% + pc% + 7 'Lower row of display area
- y2% = 79 'Right col of display area
-
- ClearBox x1%, y1%, x2%, y2% 'Clear area for display
-
- c% = 0 'Initialize line counter
- DO
- c% = c% + 1
- IF NOT MyDir(c%).DirectoryFlag THEN NS = NS + MyDir(c%).EntrySize
- IF MyDir(c%).ReadOnlyFlag THEN RS = RS + MyDir(c%).EntrySize
- IF MyDir(c%).HiddenFlag THEN HS = HS + MyDir(c%).EntrySize
- IF MyDir(c%).SystemFlag THEN SS = SS + MyDir(c%).EntrySize
- IF MyDir(c%).ArchiveFlag THEN XS = XS + MyDir(c%).EntrySize
- LOOP UNTIL c% = HoldCount% + SubDir%
- t% = 1
- WHILE t% <= HoldCount% + SubDir%
- IF MyDir(t%).ReadOnlyFlag THEN TR% = TR% + 1
- IF MyDir(t%).HiddenFlag THEN TH% = TH% + 1
- IF MyDir(t%).SystemFlag THEN TS% = TS% + 1
- IF MyDir(t%).ArchiveFlag THEN TA% = TA% + 1
- t% = t% + 1
- WEND
- c$ = "Attrib Total bytes"
- GOSUB PrintLine
- ReverseLine BoxRow% + pc% - 1, BoxCol2% + 2, 79
- c$ = "Reserved: " + MaskIt$(STR$(TR%), fl%, "R") + br$ + MaskIt$(STR$(RS), fl%, ",")
- GOSUB PrintLine
- c$ = "Hidden : " + MaskIt$(STR$(TH%), fl%, "R") + br$ + MaskIt$(STR$(HS), fl%, ",")
- GOSUB PrintLine
- c$ = "System : " + MaskIt$(STR$(TS%), fl%, "R") + br$ + MaskIt$(STR$(SS), fl%, ",")
- GOSUB PrintLine
- c$ = "Archived: " + MaskIt$(STR$(TA%), fl%, "R") + br$ + MaskIt$(STR$(XS), fl%, ",")
- GOSUB PrintLine
- c$ = "Files Total bytes"
- GOSUB PrintLine
- ReverseLine BoxRow% + pc% - 1, BoxCol2% + 2, 79
- SELECT CASE SubDir%
- CASE True%
- c$ = "Sub-dirs: " + MaskIt$(STR$(MyDirCount% - SubDir%), fl%, "R") + br$
- CASE False%
- c$ = "Dirs : " + MaskIt$(STR$(MyDirCount%), fl%, "R") + br$
- END SELECT
- GOSUB PrintLine
- c$ = "Non-Dir : " + MaskIt$(LTRIM$(STR$(HoldCount% - MyDirCount% + SubDir%)), fl%, "R") + br$ + MaskIt$(STR$(NS), fl%, ",")
- GOSUB PrintLine
-
- GOTO ExitDisplayDirStats
-
- PrintLine:
- LOCATE BoxRow% + pc%, BoxCol3%
- PRINT c$;
- pc% = pc% + 1
- RETURN
-
- ExitDisplayDirStats:
- END SUB
-
- SUB DisplayHelp
-
- LOCATE 23, 1
- PRINT " ESC = Exit "; CHR$(17); CHR$(196); CHR$(217);
- PRINT " = Up/Down (on < DIR >) A-Z = Select file/dir";
- ReverseLine 23, 1, 5
- ReverseLine 23, 21, 25
- ReverseLine 23, 56, 60
- LOCATE 24, 1
- PRINT " F2 = Display total bytes used by highlighted dir and all sub-dirs";
- ReverseLine 24, 7, 10
-
- ExitDisplayHelp:
- END SUB
-
- SUB DisplayMemStats
-
- x1% = LastBoxRow% + 4 'Upper row of display area
- y1% = BoxCol1% 'Left col of display area
- x2% = x1% + 3 'Lower row of display area
- y2% = BoxCol2% 'Right col of display area
-
- ClearBox x1% - 1, y1%, x2%, y2% 'Clear display area
-
- Center x1%, y1%, y2%, "Memory" 'Create header
- ReverseLine x1%, y1%, y2% 'Create header line
-
- MA$ = MaskIt$(STR$(FRE(-1)), 7, ",") 'Calc avail memory
- CALL INTERRUPTX(&H12, InRegsX, OutRegsX) 'Make interrupt call
- MemKB = OutRegsX.AX 'Get total memory (in KiloBytes)
- Mem = MemKB * 1024 'Available memory (total bytes)
- TM$ = MaskIt$(STR$(Mem), 7, ",") 'Get total memory
-
- ' Display statistics
- Center x1% + 1, y1%, y2%, TM$ + " Bytes Total Memory"
- Center x1% + 2, y1%, y2%, MA$ + " Bytes Memory Free "
- ReverseLine x1% + 3, y1%, y2%
-
- ExitDisplayMemStats:
- END SUB
-
- SUB DisplayTotals STATIC
-
- IF TotalsDisplayed% = False% THEN
- d$ = LEFT$(CurrentDir$, 1) 'Get current drive letter
- t% = ASC(d$) - 64 'Set correct drive value(A=1,etc)
- InRegsX.AX = &H3600 'AH=Hex 36 (function)
- InRegsX.DX = t% 'DL=Drive number
- CALL INTERRUPTX(&H21, InRegsX, OutRegsX) 'Interrupt 21
- AXReg& = OutRegsX.AX 'AX Register value
- SectorsPerCluster& = AXReg& AND 255 'AL=Sectors per cluster
- AvailClusters& = OutRegsX.BX 'Get space available on disk
- SectorSize& = OutRegsX.CX 'CX=Sector size (in bytes)
- TotalClusters& = OutRegsX.DX 'DX=Total number clusters on disk
- TotalAvail& = SectorsPerCluster& * SectorSize& * AvailClusters&
- InRegsX.AX = &H1C00 'AH=Hex 1C (function)
- InRegsX.DX = t% 'DL=Drive number
- CALL INTERRUPTX(&H21, InRegsX, OutRegsX) 'Interrupt 21
- SectorsPerCluster& = OutRegsX.AX AND 255 'AL=Sectors per cluster
- Descriptor% = OutRegsX.BX 'BX=Offset of descriptor info
- SectorSize& = OutRegsX.CX 'CX=Sector size (in bytes)
- BufferSegment% = OutRegsX.DS 'DS=Segment of descriptor info
- TotalClusters& = OutRegsX.DX 'DX=Total number clusters on disk
- DEF SEG = BufferSegment% 'Set memory segment to descriptor's
- Descriptor$ = HEX$(PEEK(Descriptor%)) 'Get the thing
- DEF SEG 'Set back to Basic
- TotalBytes& = SectorsPerCluster& * SectorSize& * TotalClusters&
-
- Center LastBoxRow% + 1, BoxCol1%, BoxCol2%, "Drive " + d$ + ":"
- ReverseLine LastBoxRow% + 1, BoxCol1%, BoxCol2%
- t$ = MaskIt$(STR$(TotalBytes&), 20, ",") + " total bytes on drive " + d$ + ":"
- Center LastBoxRow% + 2, BoxCol1%, BoxCol2%, t$
- t$ = MaskIt$(STR$(TotalAvail&), 20, ",") + " bytes available drive " + d$ + ":"
- Center LastBoxRow% + 3, BoxCol1%, BoxCol2%, t$
- END IF
- TotalsDisplayed% = True%
-
- END SUB
-
- SUB DoKeystroke
-
- ' This subroutine accepts input from the keyboard, determines it's
- ' validity, and takes the correct action (if any is needed)
-
- GetKeystroke:
- Action% = False%
- DO
- K$ = INKEY$
- LOOP WHILE K$ = null$
- Keys% = (ASC(RIGHT$(K$, 1)))
- ScanKey% = (ASC(LEFT$(K$, 1)))
- ValidKey% = True%: DoReverseLine% = True%
- IF ScanKey% = 0 THEN
- SELECT CASE Keys%
- CASE 60 '<F2> key
- t$ = RTRIM$(MyDir(DirChoice%).EntryName)
- IF t$ = ".." OR MyDir(DirChoice%).DirectoryFlag <> 16 THEN
- BEEP
- ELSE
- IF SubDir% THEN s$ = "\" ELSE s$ = null$
- GrandTotals CurrentDir$ + s$ + t$
- END IF
- DoReverseLine% = False%
- CASE 71 '<HOME> key
- IF DirChoice% <> 1 THEN
- IF TopDisplay% <> 1 THEN
- OldLine% = 1
- NewLine% = 1
- DirChoice% = 1
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (DirChoice%)
- ReverseLine FirstPrintRow%, BoxCol1%, BoxCol2%
- DoReverseLine% = False%
- ELSE
- OldLine% = NewLine%
- DirChoice% = 1
- NewLine% = 1
- END IF
- ELSE
- DoReverseLine% = False%
- END IF
- CASE 72 '<UP ARROW> key
- IF DirChoice% = 1 THEN
- NewLine% = 1
- OldLine% = NewLine%
- DoReverseLine% = False%
- ELSE
- IF NewLine% = 1 THEN
- DirChoice% = DirChoice% - 1
- ScrollDown CreateBoxLine$(DirChoice%)
- OldLine% = NewLine% + 1
- NewLine% = 1
- TopDisplay% = TopDisplay% - 1
- BottomDisplay% = BottomDisplay% - 1
- ELSE
- OldLine% = NewLine%
- NewLine% = NewLine% - 1
- DirChoice% = DirChoice% - 1
- END IF
- END IF
- CASE 73 '<PGUP> key
- IF DirChoice% > LastPrintLine% THEN
- DirChoice% = DirChoice% - LastPrintLine%
- IF DirChoice% > LastPrintLine% THEN
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (DirChoice%)
- ReverseLine FirstPrintRow%, BoxCol1%, BoxCol2%
- OldLine% = 1
- NewLine% = OldLine%
- DoReverseLine% = False%
- ELSE
- temp% = 1
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (temp%)
- temp% = FirstPrintRow% + DirChoice% - temp%
- ReverseLine temp%, BoxCol1%, BoxCol2%
- OldLine% = DirChoice%
- NewLine% = OldLine%
- DoReverseLine% = False%
- END IF
- ELSE
- IF DirChoice% <> NewLine% THEN
- DirChoice% = 1
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (DirChoice%)
- ReverseLine FirstPrintRow%, BoxCol1%, BoxCol2%
- OldLine% = 1
- NewLine% = OldLine%
- DoReverseLine% = False%
- ELSE
- IF DirChoice% = 1 THEN
- DoReverseLine% = False%
- ELSE
- DirChoice% = 1
- OldLine% = NewLine%
- NewLine% = 1
- END IF
- END IF
- END IF
- CASE 79 '<END> key
- IF DirChoice% <> HoldCount% + SubDir% THEN
- IF BottomDisplay% <> HoldCount% + SubDir% THEN
- DirChoice% = HoldCount% + SubDir% - LastPrintLine% + 1
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (DirChoice%)
- ReverseLine LastPrintRow%, BoxCol1%, BoxCol2%
- OldLine% = NewLine%
- NewLine% = LastPrintLine%
- DirChoice% = HoldCount% + SubDir%
- DoReverseLine% = False%
- ELSE
- OldLine% = NewLine%
- DirChoice% = HoldCount% + SubDir%
- NewLine% = LastPrintLine%
- END IF
- ELSE
- DoReverseLine% = False%
- END IF
- CASE 80 '<DOWN ARROW> key
- IF DirChoice% = HoldCount% + SubDir% THEN
- NewLine% = LastPrintLine%
- OldLine% = NewLine%
- DoReverseLine% = False%
- ELSE
- IF NewLine% = LastPrintLine% THEN
- DirChoice% = DirChoice% + 1
- ScrollUp CreateBoxLine$(DirChoice%)
- OldLine% = NewLine% - 1
- NewLine% = LastPrintLine%
- TopDisplay% = TopDisplay% + 1
- BottomDisplay% = BottomDisplay% + 1
- ELSE
- OldLine% = NewLine%
- NewLine% = NewLine% + 1
- DirChoice% = DirChoice% + 1
- END IF
- END IF
- CASE 81 '<PGDN> key
- IF DirChoice% + LastPrintLine% <= HoldCount% + SubDir% THEN
- DirChoice% = DirChoice% + LastPrintLine%
- IF DirChoice% + LastPrintLine% <= HoldCount% + SubDir% THEN
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (DirChoice%)
- ReverseLine FirstPrintRow%, BoxCol1%, BoxCol2%
- OldLine% = NewLine%
- NewLine% = 1
- DoReverseLine% = False%
- ELSE
- temp% = HoldCount% + SubDir% - LastPrintLine% + 1
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (temp%)
- temp% = LastPrintRow% - (HoldCount% + SubDir% - DirChoice%)
- ReverseLine temp%, BoxCol1%, BoxCol2%
- temp% = temp% - FirstPrintRow% + 1
- OldLine% = temp%
- NewLine% = temp%
- DoReverseLine% = False%
- END IF
- ELSE
- IF DirChoice% = HoldCount% + SubDir% THEN
- DoReverseLine% = False%
- ELSE
- OldLine% = NewLine%
- NewLine% = LastPrintLine%
- DirChoice% = HoldCount% + SubDir%
- END IF
- END IF
- CASE ELSE
- ValidKey% = False% 'If not done above, invalid keypress
- END SELECT
- ELSE
- SELECT CASE Keys%
- CASE 13 '<ENTER> key
- SELECT CASE RTRIM$(MyDir(DirChoice%).EntryName)
- CASE ".."
- SaveDir$ = CurrentDir$
- NewDir$ = LEFT$(SaveDir$, LastOccurrence%(SaveDir$, "\") - 1)
- IF RIGHT$(NewDir$, 1) = ":" THEN NewDir$ = NewDir$ + "\"
- GOTO ChangeDir
- CASE ELSE
- IF MyDir(DirChoice%).DirectoryFlag THEN
- NewDir$ = CurrentDir$
- IF RIGHT$(NewDir$, 1) <> "\" THEN NewDir$ = NewDir$ + "\"
- NewDir$ = NewDir$ + MyDir(DirChoice%).EntryName
- GOTO ChangeDir
- ELSE
- OldLine% = NewLine%
- DoReverseLine% = False%
- END IF
- END SELECT
- CASE 27 '<ESC> key
- Action% = EndIt%
- EXIT SUB
- CASE 65 TO 90, 97 TO 122 '<A> - <Z> (ALPHA) keys
- SELECT CASE Keys%
- CASE 97 TO 122
- Keys% = Keys% - 32
- END SELECT
- t$ = CHR$(Keys%)
- c% = DirChoice%
- StartPoint% = c%
- EndPoint% = UBOUND(MyDir)
- DO
- c% = c% + 1
- IF c% >= EndPoint% THEN c% = 0
- IF c% = StartPoint% THEN EXIT DO
- LOOP UNTIL t$ = LEFT$(MyDir(c%).EntryName, 1)
- IF c% <> StartPoint% THEN
- IF c% >= TopDisplay% AND c% <= BottomDisplay% THEN
- OldLine% = NewLine%
- NewLine% = c% - TopDisplay% + 1
- DirChoice% = c%
- ELSE
- IF c% < LastPrintLine% THEN
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (1)
- ReverseLine FirstPrintRow% + c% - 1, BoxCol1%, BoxCol2%
- DirChoice% = c%
- OldLine% = c%
- NewLine% = c%
- DoReverseLine% = False%
- ELSE
- IF c% + LastPrintLine% > HoldCount% + SubDir% THEN
- temp% = HoldCount% + SubDir% - LastPrintLine% + 1
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (temp%)
- temp% = c% - TopDisplay% + FirstPrintRow%
- ReverseLine temp%, BoxCol1%, BoxCol2%
- temp% = temp% - FirstPrintRow% + 1
- OldLine% = temp%
- NewLine% = OldLine%
- DirChoice% = c%
- DoReverseLine% = False%
- ELSE
- ClearBox FirstPrintRow%, BoxCol%, LastPrintRow%, BoxCol1% + BoxLength%
- DisplayDir (c%)
- ReverseLine FirstPrintRow%, BoxCol1%, BoxCol2%
- OldLine% = 1
- NewLine% = OldLine%
- DirChoice% = c%
- DoReverseLine% = False%
- END IF
- END IF
- END IF
- ELSE
- DoReverseLine% = False%
- END IF
- CASE ELSE
- ValidKey% = False% 'If not done above, invalid keypress
- END SELECT
- END IF
- IF ValidKey% = True% THEN 'Good keystroke?
- IF DoReverseLine% THEN 'To eliminate snow at top or bottom
- ReverseLine FirstPrintRow% + OldLine% - 1, BoxCol1%, BoxCol2% 'Replace old
- ReverseLine FirstPrintRow% + NewLine% - 1, BoxCol1%, BoxCol2% 'Move bar
- END IF
- END IF
-
- GOTO GetKeystroke
-
- ChangeDir:
- CHDIR NewDir$
- Action% = NextDir%
-
- END SUB
-
- SUB ExitLogo
-
- x1% = LastBoxRow% + 1
- y1% = BoxCol2% + 2
- x2% = 22
- y2% = 79
-
- ClearBox x1% - 1, y1% - 1, x2%, y2%
-
- ReverseLine x1%, y1%, y2%
- Center x1% + 1, y1%, y2%, "Fairchild Computer Services"
- Center x1% + 2, y1%, y2%, "Route 5, Box 523-12"
- Center x1% + 3, y1%, y2%, "Wills Point, TX 75169"
- Center x1% + 4, y1%, y2%, "(903) 873-2114"
- Center x1% + 5, y1%, y2%, "Have a great day!!"
- ReverseLine x1% + 6, y1%, y2%
-
- ClearBox 22, 1, 24, 80
- LOCATE 22, 1
-
- END SUB
-
- SUB GetDir
-
- 'Get/Sort directory entries
-
- SubDir% = False% 'Init Sub directory flag
- SELECT CASE HoldCount% 'How many we gettin?
- CASE 0 'None?
- CASE ELSE ' or some?
- c% = 1 'Initialize counter
- t$ = Dir$("*.*") 'Initialize temporary variable
- DO 'Begin entry-getting loop
- MyDir(c%) = DirRecord 'Load DirRecord into array
- c% = c% + 1 'Increment counter
- IF RTRIM$(t$) = "." THEN 'Upper directory name?
- c% = c% - 1 ' if so, decrement counter
- HoldCount% = HoldCount% - 1 ' and totals counter
- END IF
- IF RTRIM$(t$) = ".." THEN 'Is this a subdirectory?
- SubDir% = True% 'yep...
- HoldCount% = HoldCount% - 1 'decrement totals counter
- END IF
- t$ = Dir$(null$) 'Call for next entry
- LOOP UNTIL t$ = null$ 'Keep goin until none found
- SortDir HoldCount% + SubDir% 'Sort em
- END SELECT
-
- END SUB
-
- SUB GrandTotals (Directory$)
-
- x1% = BoxRow% + 9 'Upper row of display area
- y1% = BoxCol2% + 2 'Left col of display area
- x2% = x1% + 4 'Lower row of display area
- y2% = 79 'Right col of display area
-
- all$ = "\*.*" 'Save wildcard search to variable
- Directory$ = Directory$ + all$ 'Name directory we're totaling
- RootDir$ = LEFT$(Directory$, INSTR(Directory$, all$) - 1)
- t% = LastOccurrence%(RootDir$, "\") + 1
- RootDir$ = MID$(RootDir$, t%, 99) 'Save root dir name for later print
- REDIM GTDir$(1000) 'Number of sub-dir levels we can go
-
- c% = 0 'Init temp counter
- SC% = c% 'Init sub-dir counter variable
- GTDir$(c%) = Directory$ 'First dir/level
- DO
- t$ = Dir$(GTDir$(c%)) 'Get directory entry
- IF t$ <> null$ THEN 'Did we get one?
- DO 'Yep, let's get some more!
- IF LEFT$(t$, 1) <> "." AND DirRecord.DirectoryFlag THEN 'Dir type?
- SC% = SC% + 1 'Yep, increment sub-dir count
- GTDir$(SC%) = LEFT$(Directory$, INSTR(Directory$, all$)) + RTRIM$(DirRecord.EntryName) + all$
- END IF
- t$ = Dir$(null$) 'Get next entry
- LOOP UNTIL t$ = null$ 'Last one?
- END IF 'Yep...
- IF c% <> SC% THEN 'Got all our sub-dir names yet?
- c% = c% + 1 ' nope, try again
- Directory$ = GTDir$(c%) ' and reset dir variable
- ELSE
- EXIT DO
- END IF
- LOOP
-
- c% = 0 'Init temp counter
- FC = 0 'Init file counter variable
- TS# = 0 'Init temp total variable
- DO 'Start loop
- t$ = Dir$(GTDir$(c%)) 'Get directory entry
- IF t$ <> null$ THEN 'Did we get one?
- DO 'Yep, let's get some more!
- TS# = TS# + DirRecord.EntrySize
- IF LEFT$(t$, 1) <> "." AND DirRecord.DirectoryFlag <> 16 THEN 'Dir?
- FC = FC + 1
- END IF
- t$ = Dir$(null$) 'Get next entry
- LOOP UNTIL t$ = null$ 'Last one?
- END IF 'Yep...
- c% = c% + 1
- LOOP UNTIL c% > SC%
-
- PrintGrandTotals:
-
- ClearBox x1% - 1, y1%, x2%, y2%
-
- Center x1%, y1% + 1, y2%, "GrandTotals - " + RootDir$ + "..."
- ReverseLine x1%, y1%, y2%
- IF FC = 1 THEN t1$ = " total file" ELSE t1$ = " total files"
- t$ = MaskIt$(LTRIM$(STR$(FC)), 15, ",") + t1$
- Center x1% + 1, y1%, y2%, t$
- IF SC = 1 THEN t1$ = " subdirectory" ELSE t1$ = " subdirectories"
- t$ = MaskIt$(LTRIM$(STR$(SC%)), 15, ",") + t1$
- Center x1% + 2, y1%, y2%, t$
- IF TS# = 1 THEN t1$ = " Byte used" ELSE t1$ = " Bytes used"
- t$ = MaskIt$(LTRIM$(STR$(TS#)), 15, ",") + t1$
- Center x1% + 3, y1%, y2%, t$
- ReverseLine x1% + 4, y1%, y2%
- REDIM GTDir$(1)
-
- ExitGrandTotals:
- END SUB
-
- FUNCTION LastOccurrence% (text$, LookString$)
-
- ' This function will search through the string LookString$ for text$
- ' and return the location of it's last occurence
-
- c% = False% 'Init counter to 0
- found% = True% 'Init found flag
- DO UNTIL found% = False% 'Keep looking for string until done
- found% = INSTR(c% + 1, text$, LookString$) 'Found one!!
- IF found% THEN c% = found% 'Save counter
- LOOP
-
- LastOccurrence% = c% 'Return count found
-
- END FUNCTION
-
- SUB ReverseLine (row%, lcol%, rcol%)
-
- ' This subroutine will reverse video the characters on row%, between
- ' lcol% and rcol% (color only). It directly accesses the video memory
- ' segment to do the color changes.
-
- PokeCount% = 0 'Init character counter
- length% = (rcol% - lcol% + 1) * 2 'Calculate ending offset
- PosStart% = row% * 80 - 160 + lcol% * 2 + 1 'Video RAM addr begin POKEing
- vidseg = VideoSegment 'Get video memory segment address
- DEF SEG = vidseg 'Set memory seg address to our CRT
- PokePos% = PosStart% + row% * 80 'Calc strt screen pos for POKE
- PokeLength% = PokePos% + length% 'Calculate last POKEing address
- DO 'Start column loop
- d% = PEEK(PokePos%) 'Do repeated calculation
- POKE PokePos%, (d% AND 15) * 16 + d% / 16 'Reverse color
- PokePos% = PokePos% + 2 'Increment POKE position counter
- LOOP UNTIL PokePos% = PokeLength% 'Loop until end of line
- DEF SEG 'Return to BASIC segment
-
- END SUB
-
- SUB ScrollDown (text$)
-
- ' This subroutine will scroll the contents of a window down 1 line.
- ' The text$ is what is to be inserted at the top of the window
- ' after the scroll.
-
- InRegsX.AX = &H700 + 1 'function 7 + number of scroll lines
- fg% = MainFg% * 256 'Calc BH foreground
- bg% = MainBg% * 4096 'Calc BH background
- InRegsX.BX = fg% + bg% 'Blanked line color
- CH% = (FirstPrintRow% - 1) * 256 'CH=top row
- InRegsX.CX = CH% + BoxCol% 'CL=left column
- DH% = (LastPrintRow% - 1) * 256 'DH=bottom row
- InRegsX.DX = DH% + BoxCol% + BoxLength% 'DL=right column
- CALL INTERRUPTX(&H10, InRegsX, OutRegsX) 'Call interrupt 16
- LOCATE FirstPrintRow%, BoxCol% + 1 'Locate cursor for top line print
- PRINT text$; 'Print the top line
-
- END SUB
-
- SUB ScrollUp (text$)
-
- ' This subroutine will scroll the contents of a window up one line.
- ' The text$ is what is to be inserted at the bottom of the window
- ' after the scroll.
-
- InRegsX.AX = &H600 + 1 'function 6 + number of scroll lines
- fg% = MainFg% * 256 'Calc BH foreground
- bg% = MainBg% * 4096 'Calc BH background
- InRegsX.BX = fg% + bg% 'Blanked line color
- CH% = (FirstPrintRow% - 1) * 256 'CH=top row
- InRegsX.CX = CH% + BoxCol% 'CL=left column
- DH% = (LastPrintRow% - 1) * 256 'DH=bottom row
- InRegsX.DX = DH% + BoxCol% + BoxLength% 'DL=right column
- CALL INTERRUPTX(&H10, InRegsX, OutRegsX) 'Call interrupt 16
- LOCATE LastPrintRow%, BoxCol% + 1 'Locate cursor for bottom line print
- PRINT text$; 'Print the bottom line
-
- END SUB
-
- SUB SortDir (count%)
-
- Center FirstPrintRow%, BoxCol1%, BoxCol2%, "...One moment, I'm sorting 'em..."
-
- ' First, separate out dir entries
- DIM temp(count%) AS DirType
- MyDirCount% = 0
- FOR c% = 1 TO count%
- IF MyDir(c%).DirectoryFlag THEN
- SWAP MyDir(c%), temp(c%)
- MyDirCount% = MyDirCount% + 1
- END IF
- NEXT
-
- ' Sort everything BUT directory entries
- DO
- Swaps% = False%
- FOR c% = 1 TO count% - 1
- IF MyDir(c%).EntryName > MyDir(c% + 1).EntryName THEN
- SWAP MyDir(c%), MyDir(c% + 1)
- Swaps% = True%
- END IF
- NEXT c%
- LOOP WHILE Swaps%
-
- ' Then, sort the dir entries
- DO
- Swaps% = False%
- FOR c% = 1 TO count% - 1
- IF temp(c%).EntryName > temp(c% + 1).EntryName THEN
- SWAP temp(c%), temp(c% + 1)
- Swaps% = True%
- END IF
- NEXT c%
- LOOP WHILE Swaps%
-
- ' ... And insert em.
- StartPoint% = count% - MyDirCount% + 1
- d% = 1
- FOR c% = StartPoint% TO count%
- SWAP MyDir(d%), temp(c%)
- d% = d% + 1
- NEXT
-
- END SUB
-
- FUNCTION VideoSegment
-
- ' This is a handy function to return the memory address of the video
- ' memory segment.
-
- VS = PEEK(&H63) + PEEK(&H64) * 256 'Get CRT controller port
- IF VS = &H3B4 THEN
- VS = &HB000 'Video RAM segment address (mono)
- ELSE
- VS = &HB800 'Video RAM segment address (color)
- END IF
-
- VideoSegment = VS 'Return variable value
-
- END FUNCTION
-
-